package com.comdefinition.controller

import com.comdefinition.modals.User
import groovy.transform.CompileStatic
import groovy.transform.TypeChecked
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.ui.ModelMap
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.ResponseBody

/**
 * Created by hp4664 on 2017/9/15.
 */
@TypeChecked
@CompileStatic
@Controller
@RequestMapping("/page/")
class LoginController {

    /**
     * 登录页面
     * @param map
     * @return
     */
    @RequestMapping("login")
    String login(Model map) {
        User user=new User(id: 1,name: "测试一",age: 10)
        map.addAttribute("user", user)
        return "login"
    }

    /**
     * 登录操作
     * @param user
     * @param model
     * @return
     */
    @PostMapping("/loginOn")
    public String bb(User user, Model model) {
        model.addAttribute("user", user)
        model.addAttribute("message", ",welcome")
        return "index"
    }


    @RequestMapping(value = "/list")
    public String customers(ModelMap map) {
        def list = []
        for (int i = 0; i < 5; i++) {
            def obj = [
                    "id"  : i,
                    "name": "siva" + i,
                    "age" : i + 10
            ]
            list.add(obj)
        }
        map.addAttribute("data", list);
        return "userList"
    }
}
